package com.dtx.service.impl;

import com.dtx.dao.IExamDao;
import com.dtx.domain.Exam;
import com.dtx.service.IExamService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ExamServiceImpl implements IExamService {

    @Autowired
    private IExamDao examDao;

    @Override
    public List<Exam> findAll(int page, int size) throws Exception {
        //参数pageNum是页码值，参数pageSize代表是每页显示条数
        PageHelper.startPage(page,size);
        return examDao.findAll();
    }

    @Override
    public void save(Exam exam) throws Exception {
        examDao.save(exam);
    }

    @Override
    public void deleteExamById(Integer id) throws Exception {
        examDao.deleteExamById(id);
    }

    @Override
    public void update(Exam exam) throws Exception {
        examDao.update(exam);
    }

    @Override
    public Exam findById(Integer id) throws Exception {
        return examDao.findById(id);
    }

    @Override
    public List<Exam> findExamByName(String name) throws Exception {
        return examDao.findExamByName("%"+name+"%");
    }
}
